package com.itboye.mengwu.data.presenter;

import java.util.List;
import java.util.Observer;

import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.core.object.BasePresenter;
import com.itboye.core.object.ResultEntity;
import com.itboye.mengwu.app.ui.main.MainPresenter;
import com.itboye.mengwu.data.interfaces.IOrder;
import com.itboye.mengwu.data.model.OrderBean;
import com.itboye.mengwu.data.repository.OrderRepository;

public class OrderPresenter extends BasePresenter implements IOrder<OrderBean> {
	// 生成订单
	public static final String OrderShengchengSuccess = MainPresenter.class
			.getName() + "_OrderShengcheng_success";
	public static final String OrderShengchengFail = MainPresenter.class
			.getName() + "_OrderShengcheng_failure";
	// 获取店铺优惠
	public static final String getFavourableSuccess = MainPresenter.class
			.getName() + "_getFavourable_success";
	public static final String getFavourableFail = MainPresenter.class
			.getName() + "_getFavourable_failure";
	// 订单分页查询
	public static final String OrderQuerySuccess = MainPresenter.class
			.getName() + "_OrderQuery_success";
	public static final String OrderQueryFail = MainPresenter.class.getName()
			+ "_OrderQuery_failure";

	public static final String OrderDeleteSuccess = MainPresenter.class
			.getName() + "_OrderDelete_success";
	public static final String OrderDeleteFail = MainPresenter.class.getName()
			+ "_OrderDelete_fail";
	// 确认订单
	public static final String OrderSureSuccess = MainPresenter.class.getName()
			+ "_OrderSure_success";
	public static final String OrderSureFail = MainPresenter.class.getName()
			+ "_OrderSure_fail";

	// 申请售后
	public static final String ShenQingSuccess = MainPresenter.class.getName()
			+ "_ShenQingShouHou_success";
	public static final String ShenQingFail = MainPresenter.class.getName()
			+ "_ShenQingShouHou_fail";
	//立即支付
	public static String PayInstant_success = MainPresenter.class.getName()
			+ "_PayInstant_success";
	public static String PayInstant_Fail = MainPresenter.class.getName()
			+ "_PayInstant_Fail";

	//评论订单
	public static final String CommentOrderSuccess = "CommentOrderSuccess";
	public static final String CommentOrderFail = "CommentOrderFail";
	
	//搭配购详情
		public static final String DapeigouSuccess = "DapeigouSuccess";
		public static final String DapeigouFail = "DapeigouFail";

	public OrderPresenter(Observer observer) {
		super(observer);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void add(OrderBean model) {
		// TODO Auto-generated method stub
		IOrder<OrderBean> addGoods = new OrderRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(OrderShengchengSuccess);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(OrderShengchengFail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.add(model);// ("", "", "", "");

	}

	@Override
	public void delete(OrderBean model) {
		// TODO Auto-generated method stub
		IOrder<OrderBean> addGoods = new OrderRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(OrderDeleteSuccess);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(OrderDeleteFail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.delete(model);// ("", "", "", "");
	}

	@Override
	public void update(OrderBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void getInfo(OrderBean model) {
		// TODO Auto-generated method stub
		IOrder<OrderBean> addGoods = new OrderRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(OrderQuerySuccess);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(OrderQueryFail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.getInfo(model);// ("", "", "", "");
	}

	@Override
	public List<OrderBean> query(OrderBean model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void getXiangQing(String id) {
		// TODO Auto-generated method stub
		IOrder<OrderBean> addGoods = new OrderRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(OrderQuerySuccess);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(OrderQueryFail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.getXiangQing(id);// ("", "", "", "");
	}

	@Override
	public void makesureOrder(String uid, String orderCode) {
		// TODO Auto-generated method stub
		IOrder<OrderBean> addGoods = new OrderRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(OrderSureSuccess);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(OrderSureFail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.makesureOrder(uid, orderCode);// ("", "", "", "");
	}

	@Override
	public void shenQingShouHou(String uid, String orderCode, String money,
			String reason, String backtype, boolean isGoodsGet, String note) {
		// TODO Auto-generated method stub
		IOrder<OrderBean> addGoods = new OrderRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(ShenQingSuccess);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(ShenQingFail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.shenQingShouHou(uid, orderCode, money, reason, backtype,
				isGoodsGet, note);// ("", "", "", "");
	}

	@Override
	public void buyInstant(String uid, String pid, String count, String pskuId,
			String redId, String couponId, String money, String note,
			String addressId, String form,String packageId) {
		// TODO Auto-generated method stub
		IOrder<OrderBean> addGoods = new OrderRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(PayInstant_success);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(PayInstant_Fail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.buyInstant(uid, pid, count, pskuId, redId, couponId, money,
				note, addressId, form,packageId);
	}

	@Override
	public void commentOrder(String uid, String pid, String orderCode,
			String pskuId, String groupId, String packageId, String score,
			String[] comment, String imgs, String expressScore,
			String deliveryScore, String serviceScore) {
		// TODO Auto-generated method stub
		IOrder<OrderBean> addGoods = new OrderRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(CommentOrderSuccess);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(CommentOrderFail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.commentOrder(uid, pid, orderCode, pskuId, groupId, packageId,
				score, comment, imgs, expressScore, deliveryScore, serviceScore);
	}

	@Override
	public void getStoreFavourable(String storeId) {
		// TODO Auto-generated method stub
		IOrder<OrderBean> addGoods = new OrderRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(getFavourableSuccess);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(getFavourableFail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.getStoreFavourable(storeId);
	}

	@Override
	public void dapeigou(String packageId) {
		// TODO Auto-generated method stub
		
		IOrder<OrderBean> addGoods = new OrderRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(DapeigouSuccess);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(DapeigouFail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.dapeigou(packageId);
	}

}